<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <div class="content">
        <div class="panel panel-default panel-intro">

            <div class="panel-body">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in" id="one">
                        <div class="widget-body no-padding">

                            <div class="bootstrap-table">
                                <div class="commonsearch-table ">
                                    <fieldset>
                                        <div class="row">
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="c-supplier_id" class="control-label col-xs-4">单据类型</label>
                                                <div class="col-xs-8">
                                                    <select name="" id="type" class="form-control">
                                                        <option value="1"   {if condition="$row.type eq 1"}selected {else /} {/if}>采购</option>
                                                        <option value="2" {if condition="$row.type eq 2"}selected {else /} {/if}>销售</option>
                                                    </select>
                                                </div>
                                            </div>

                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="c-supplier_id" class="control-label col-xs-4">供应商</label>
                                                <div class="col-xs-8">
                                                    <input id="c-supplier_id"  data-source="supplier/supplier/index" data-field="nickname" class="form-control selectpage" name="supplier_id" type="text" value="{$row.supplier_id}">
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="c-customer_id" class="control-label col-xs-4">单据编号</label>
                                                <div class="col-xs-8">
                                                    <input id="c-number" data-rule="required"   class="form-control c-number" name="number" type="text" value="{$row.source_number}" disabled>
                                                    <input    class="form-control c-number" name="number" type="hidden" value="{$row.source_number}" >
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="c-customer_id" class="control-label col-xs-4">客户</label>
                                                <div class="col-xs-8">
                                                    <input id="c-customer_id"    class="form-control " name="customer_id" type="text" value="{$company}" disabled>
                                                    <input id="" data-rule="required"  class="form-control c-customer_id" name="customer_id" type="hidden" value="{$row.customer_id}" >
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="explain" class="control-label col-xs-4">说明</label><div class="col-xs-8">
                                                <input type="text" class="form-control" name="explain" value="{$row.explain}" placeholder="说明" id="explain" data-index="13">
                                            </div>

                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3" >
                                                <label for="allfare" class="control-label col-xs-4">运费</label><div class="col-xs-8">
                                                <input type="number" class="form-control" name="allfare" value="{$row.allfare}" placeholder="运费" id="allfare" data-index="14" >
                                            </div>
                                            </div>
                                        </div>
                                    </fieldset>
                                </div>
                            </div>
                            </div><div class="columns-right pull-right" style="margin-top:10px;margin-bottom:10px;">
                            </div>
                                <table id="table" class="table table-striped table-bordered table-hover table-nowrap"  data-operate-edit="1" data-operate-del="1" >
                                    <thead>
                                    <tr>
                                        <th style="text-align: center; vertical-align: middle; " data-field="id"><div class="th-inner ">Id</div></th>
                                        <!--                                <th style="text-align: center; vertical-align: middle; " data-field="createtime"><div class="th-inner ">出库仓库</div></th>-->
                                        <th style="text-align: center; vertical-align: middle; " ><div class="th-inner ">商品编号</div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="number"><div class="th-inner ">商品名称</div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="supplier_id"><div class="th-inner ">规格</div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="order_goods_total"><div class="th-inner ">销售数量</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="order_price"><div class="th-inner ">含税单价</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="order_price"><div class="th-inner ">合计</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="paid_in_price"><div class="th-inner ">差价数量</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="paid_in_price"><div class="th-inner ">当前含税单价</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="paid_in_price"><div class="th-inner ">差额</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="paid_in_price"><div class="th-inner ">税点</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="paid_in_price"><div class="th-inner ">成本差额</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">当前库存</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">当前成本价格</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">当前成本金额</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">分摊后成本金额</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">操作</div><div class="fht-cell"></div></th>
                                    </tr>
                                    </thead>
                                    <tbody data-listidx="0" class="connnn">
                                        {volist name="list" id="vo"}
                                            <tr data-index="0">
                                                <td style="text-align: center; vertical-align: middle; ">
                                                    <input name="row[{$vo.goods_id}][goods_id]" value="{$vo.id}" style="display: none" class="gid gids{$vo.goods_id}">{$vo.id}</td>
                                                <td style="text-align: center; vertical-align: middle; ">{$vo.number}</td>
                                                <td style="text-align: center; vertical-align: middle; " class="title">{$vo.title}</td>
                                                <td style="text-align: center; vertical-align: middle; ">{$vo.specs}</td>
                                                <td style="text-align: center; vertical-align: middle; " class="goods_num">{$vo.goods_num}</td>
                                                <td style="text-align: center; vertical-align: middle; " class="allprice">{$vo.ht_price}</td>
                                                <td style="text-align: center; vertical-align: middle; " class="sfhj">{$vo.sfhj}</td> <td style="text-align: center; vertical-align: middle; " class="xxgg">
                                                <input type="text" class="form-control diff_num" style="display: none" value="{$vo.diff_num}" onkeyup="this.value=this.value.replace(/\D/g,'')" name="row[{$vo.goods_id}][diff_num]">
                                                <span class="">{$vo.diff_num}</span>
                                            </td>
                                                <td style="text-align: center; vertical-align: middle; " class="xxgg">
                                                    <input type="text" class="form-control diff_price2" style="display: none" value="{$vo.diff_price2}" onkeyup="onlynumber(this);" name="row[{$vo.goods_id}][diff_price2]">
                                                    <span class="">{$vo.diff_price2}</span>
                                                </td>
                                                <td style="text-align: center; vertical-align: middle; " class="">{$vo.dsfhj}</td>
                                                <td style="text-align: center; vertical-align: middle; " class="">{$vo.dtax}</td>
                                                <td style="text-align: center; vertical-align: middle; " class="price_diff">{$vo.dbalance}</td>
                                                <td style="text-align: center; vertical-align: middle;background-color: #26b990 "class="stock" >{$vo.stock.stock}</td>
                                                <td style="text-align: center; vertical-align: middle;background-color: #26b990 ">{$vo.stock.weighting_cost}</td>
                                                <td style="text-align: center; vertical-align: middle; background-color: #26b990" class="balance">{$vo.stock.balance}</td>
                                                <td style="text-align: center; vertical-align: middle;background-color:red ">{$vo.stock.balance+$vo.dbalance}</td>
                                                <td style="text-align: center; vertical-align: middle;">
                                                    {if condition="$vo.is_share == 0"}

                                                        <a href="javascript:;" class="btn btn-xs btn-danger btn-share" data-toggle="tooltip" title="" data-table-id="table" data-field-index="15" data-row-index="0" data-button-index="2" data-original-title="分摊"><i class="fa fa-superpowers"></i></a>&nbsp;&nbsp;
                                                    {else /}
                                                        <span>已分摊</span>
                                                    {/if}
                                                </td>
                                            </tr>
                                        {/volist}
                                    </tbody>
<!--                                    <tbody class="tbfoot" data-listidx="0" style="display: ">-->
<!--                                    <td style="text-align: center; vertical-align: middle; ">合计</td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; "></td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; "></td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; " ></td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; " class="allnum">0</td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; " ></td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; "class="alprice">0</td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; "class="alldiff">0</td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; "></td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; "class="pricediff">0</td>-->
<!--                                    <td style="text-align: center; vertical-align: middle; "></td>-->
<!--                                    </tbody>-->
                                </table>
                            </div>
                            <br>
                            <div class="widget-body no-padding">
                                <div class="bootstrap-table">
                                    <div class="commonsearch-table ">
                                        <fieldset>
                                            <div class="row">
                                                <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3" style="display: none">
                                                    <label for="discount" class="control-label col-xs-4">优惠</label>
                                                    <div class="col-xs-8">
                                                        <input type="text" class="form-control " name="discount" value="0" placeholder="优惠" id="discount" data-index="7" onkeyup="checkInputIntFloat(this);">
                                                    </div>
                                                </div>
                                                <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3" style="display: none">
                                                    <label for="c-discount_explain" class="control-label col-xs-4">优惠说明</label>
                                                    <div class="col-xs-8">
                                                        <input id="c-discount-explain"   class="form-control " name="discount_explain" type="text" value="" >
                                                    </div>
                                                </div>
                                                <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3" style="display: none">
                                                    <label for="c-actual_cost" class="control-label col-xs-4">总费用</label>
                                                    <div class="col-xs-8">
                                                        <input id="c-actual-cost" data-rule="required"  class="form-control actual_cost" name="actual-cost" type="text" value="0" disabled>
                                                        <input  data-rule="required"  class="form-control actual_cost" name="actual_cost" type="text" value="0" style="display: none">
                                                    </div>
                                                </div>
                                            </div>
                                        </fieldset>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

<!--    <div class="form-group layer-footer">-->
<!--        <label class="control-label col-xs-12 col-sm-2"></label>-->
<!--        <div class="col-xs-12 col-sm-8">-->
<!--            <button type="submit" class="btn btn-success btn-embossed subpurchase">{:__('OK')}</button>-->
<!--            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>-->
<!--        </div>-->
<!--    </div>-->
</form>


<div class="form-group layer-footer">
    <label class="control-label col-xs-3 col-sm-2"></label>
    <div class="col-xs-12 col-sm-3">
        <button type="submit" class="btn btn-error btn-embossed joint-search">{:__('单据联查')}</button>
    </div>
    {if condition="$row['status'] == 2 "}
<!--    <label class="control-label col-xs-3 col-sm-2"></label>-->
<!--    <div class="col-xs-12 col-sm-3">-->
<!--        <button type="submit" class="btn btn-danger btn-embossed cancelbill {:$auth->check('coll/disparity/cancelbill')?'':'hide'}">{:__('单据红冲')}</button>-->
<!--    </div>-->
    {else /}
    {/if}
</div>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
{include file='common/adapt' /}
<script>

    $('.subpurchase').click(function () {
        var url = 'coll/disparity/finish';
        $.post(url,{ids:"{$row.id}",state:1},function (res) {
            layer.msg(res.msg)
            if(res.code == 1){
                setTimeout(function () {
                    var index = parent.Layer.getFrameIndex(window.name);
                    parent.Layer.close(index);
                    window.parent.$(".toolbar .btn-refresh").trigger('click');
                }, 800);
            }
        })

    })
    $('.reset').click(function () {
        var url = 'coll/disparity/finish';
        $.post(url,{ids:"{$row.id}",state:2},function (res) {
            layer.msg(res.msg)
            if(res.code == 1){
                setTimeout(function () {
                    var index = parent.Layer.getFrameIndex(window.name);
                    parent.Layer.close(index);
                    window.parent.$(".toolbar .btn-refresh").trigger('click');
                }, 800);
            }
        })
    })


    $('.joint-search').click(function () {
        var slip_id = "{$row.source_id}"
        var turl = '{$turl}'+'/'+'{$con}'+'/detail?ids='+slip_id
        Backend.api.addtabs(turl, '{$name}', 'fa fa-circle-o fa-fw');
    })
    // count()
    function onlynumber(ob) {
        if (!ob.value.match(/^[\+\-]?\d*?\.?\d*?$/)) ob.value = ob.t_value; else ob.t_value = ob.value; if (ob.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/)) ob.o_value = ob.value;

    }
    var is_check = 0;
    $('.subpurchase').click(function () {
        if(is_check == 0){
            var noticename = '';

            if($('.connnn').find("tr").length<1){
                layer.msg('没有选择商品')
            }
            $('.connnn').find("tr").each(function(){
                var anum = $(this).find('.requisition_num').val()
                if(anum < 1 ){
                    noticename += $(this).find('.title').html() +'&nbsp'
                }

            });
        }
    })

    function count() {
        allnum =0;
        alprice =0;
        alldiff =0;
        price_diff = 0

        $('.connnn').find("tr").each(function(){

            goods_num = $(this).find('.goods_num').html()
            allnum =allnum*1+ goods_num*1
            sfhj = $(this).find('.sfhj').html()
            alprice = alprice*1+ sfhj*1

            //--------------------------------------

            //差价数量
            diff_num = $(this).find('.diff_num').val()//数量
            alldiff= alldiff*1+diff_num*1


            diff_price = $(this).find('.price_diff').html()*1
            price_diff+=diff_price

        })
        price_diff = price_diff.toFixed(2)
        $('.allnum').html(allnum)
        $('.alprice').html(alprice.toFixed(2))
        $('.alldiff').html(alldiff)
        // $('.all_price_diff').html(price_diff)
        $('.pricediff').html(price_diff)
        $('.actual_cost').val(price_diff*1+$('#allfare').val()*1)
    }




</script>
